/**
 * 
 */
package vcp.client.GUI.mvc.controller;

import vcp.client.GUI.events.ValidationDescriptionEvent;
import vcp.client.GUI.mvc.model.UIAbstractModel;
import vcp.client.GUI.mvc.model.UILoginModel;
import vcp.client.GUI.mvc.view.UIAbstractView;
import vcp.client.GUI.mvc.view.UILoginView;
import vcp.client.interfaces.listeners.IValidationListener;
import vcp.client.utility.Common.UserNotification;
import vcp.client.utility.UtilityHelper;
import vcp.enums.PopUpMessageType;
import vcp.enums.Screen;

/**
 * 
 * @author VCP team
 *         <p>
 *         login controller
 *         </p>
 * @see UILoginView
 * @see UILoginModel
 * @see IValidationListener
 */
public class UILoginController extends UIAbstractController implements IValidationListener
{

	/**
	 * References to view and models of login
	 */
	private final UILoginView view;
	private final UILoginModel model;

	/**
	 * 
	 * @param view
	 *            get new screen
	 * @param model
	 *            info to show
	 */
	public UILoginController ( UILoginView view, UILoginModel model )
	{
		super(Screen.LOGIN);
		this.view = view;
		this.model = model;
		this.setupListeners();
	}

	// ****************************************************************************************************************************
	// UIAbstractController methods
	// ****************************************************************************************************************************
	@Override
	public UIAbstractView getView ()
	{
		return this.view;
	}

	@Override
	public UIAbstractModel getModel ()
	{
		return this.model;
	}

	@Override
	protected void setupListeners ()
	{
		super.setupListeners();
		this.view.setValidationListener(this);
	}

	@Override
	public void onButtonPress ( Object object )
	{
		this.parentDelegate.loadMVC(Screen.DEMO);
	}

	// ****************************************************************************************************************************
	// IValidationListener methods
	// ****************************************************************************************************************************
	@Override
	public void onValidationRequest ( ValidationDescriptionEvent validationEvent )
	{
		Integer loginID = validationEvent.getID();
		String password = validationEvent.getPassword();
		if ( UtilityHelper.getUtilityHelperInstance().isParamsNotNull(loginID, password) )
		{
			this.model.verifyLogin(loginID, password);
		}
		else
		{
			this.parentDelegate.showPopUpMessage(UserNotification.CANNOT_LOGIN, PopUpMessageType.ERROR);
		}
	}
}
